import {
  AccountParams,
  AccountCreateParams,
  RoleCreateParams,
  MenuCreateParams,
  MenuParams,
  RoleParams,
  RolePageParams,
  MenuListGetResultModel,
  AccountListGetResultModel,
  RolePageListGetResultModel,
  RoleListGetResultModel,
  BannerCreateParams,
} from './model/systemModel'
import { defHttp } from '/@/utils/http/axios'

enum Api {
  AccountList = '/system/getAccountList',
  CreateOrUpdateAccount = '/system/createOrUpdateAccount',
  CreateOrUpdateRole = '/system/createOrUpdateRole',
  createOrUpdateMenu = '/system/createOrUpdateMenu',
  createOrUpdateBanner = '/system/createOrUpdateBanner',
  IsAccountExist = '/system/accountExist',
  setRoleStatus = '/system/setRoleStatus',
  deleteRole = '/system/deleteRole',
  deleteMenu = '/system/deleteMenu',
  setAdminStatus = '/system/setAdminStatus',
  MenuList = '/system/getMenuList',
  MenuListTrue = '/system/getMenuListTrue',
  RolePageList = '/system/getRoleListByPage',
  GetAllRoleList = '/system/getAllRoleList',
}

export const getAccountList = (params: AccountParams) =>
  defHttp.get<AccountListGetResultModel>({ url: Api.AccountList, params })

export const getMenuList = (params?: MenuParams) =>
  defHttp.get<MenuListGetResultModel>({ url: Api.MenuList, params })

export const getAllMenuList = (params?: MenuParams) =>
  defHttp.get<MenuListGetResultModel>({ url: Api.MenuListTrue, params })

export const getRoleListByPage = (params?: RolePageParams) =>
  defHttp.get<RolePageListGetResultModel>({ url: Api.RolePageList, params })

export const getAllRoleList = (params?: RoleParams) =>
  defHttp.get<RoleListGetResultModel>({ url: Api.GetAllRoleList, params })

export const deleteRole = (id: number) =>
  defHttp.delete({ url: Api.deleteRole, params: { id } }, { successMessageMode: 'message' })

export const deleteMenu = (id: number) =>
  defHttp.delete({ url: Api.deleteMenu, params: { id } }, { successMessageMode: 'message' })

export const setRoleStatus = (id: number, status: number) =>
  defHttp.post(
    { url: Api.setRoleStatus, params: { id, status } },
    { successMessageMode: 'message' },
  )

export const setAdminStatus = (id: number, status: number) =>
  defHttp.post(
    { url: Api.setAdminStatus, params: { id, status } },
    { successMessageMode: 'message' },
  )

export const createOrUpdateAccount = (params?: AccountCreateParams) =>
  defHttp.post({ url: Api.CreateOrUpdateAccount, params }, { successMessageMode: 'message' })

export const createOrUpdateRole = (params?: RoleCreateParams) =>
  defHttp.post({ url: Api.CreateOrUpdateRole, params }, { successMessageMode: 'message' })

export const createOrUpdateMenu = (params?: MenuCreateParams) =>
  defHttp.post({ url: Api.createOrUpdateMenu, params }, { successMessageMode: 'message' })

export const createOrUpdateBanner = (params?: BannerCreateParams) =>
  defHttp.post({ url: Api.createOrUpdateBanner, params }, { successMessageMode: 'message' })

export const isAccountExist = (username: string) =>
  defHttp.post({ url: Api.IsAccountExist, params: { username } }, { errorMessageMode: 'none' })
